package brightgrove.pages;

import brightgrove.model.Film;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

/**
 * Created by alaktionov on 22.10.2014.
 */
public class AddMoviePage extends InternalPage{

    public AddMoviePage(PageManager pages) {
        super(pages);
    }

    @FindBy (name = "name")
    private WebElement titleField;

    @FindBy (name = "year")
    private WebElement yearField;

    @FindBy (name = "imdbid")
    private WebElement imdbNumber;

    @FindBy (name = "notes")
    private WebElement notesField;

    @FindBy (name = "submit")
    private WebElement saveButton;

    public String getTitle() {
        return titleField.getAttribute("value");
    }

    public String getYear() {
        return yearField.getAttribute("value");
    }

    public String getIMDB() {
        return imdbNumber.getAttribute("value");
    }

    public String getNotes() {
        return notesField.getAttribute("value");
    }

    public AddMoviePage setTitle(String title) {
        titleField.sendKeys(title);
        return this;
    }


    public AddMoviePage setYear(String year) {
        yearField.sendKeys(year);
        return this;
    }

    public AddMoviePage setIMDB(String imdb) {
        imdbNumber.sendKeys(imdb);
        return this;
    }


    public AddMoviePage setNotes(String notes) {
        notesField.sendKeys(notes);
        return this;
    }


    public void saveMovie() {
        saveButton.click();
    }

    public AddMoviePage ensurePageLoaded() {
        super.ensurePageLoaded();
        wait.until(presenceOfElementLocated(By.cssSelector("#content > section > div > div > h2")));
        return this;
    }
}
